<template>
  <div class="wifiList">
    <header>
      <h4>{{ $t('WifiList.Tip1') }}</h4>
      <p>{{ $t('WifiList.Tip2') }}</p>
    </header>
    <div class="list">
      <el-scrollbar height="100%">
        <div class="item" v-for="item in list" :key="item" @click="checkWifi(item)">
          <div class="wifiIcon"><span class="icon"></span></div>
          <span class="title">{{item.bssid}}</span>
          <div class="suoIcon"></div>
        </div>
      </el-scrollbar>
    </div>

  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";

const emit = defineEmits(['change'])

const list = ref({})
onMounted(async () => {
      const {data, code} = await wifiList()
      if (code === 200) {
        list.value = data
      }else{
        console.error('wifi名称列表数据获取失败!')
      }
    }
)

const checkWifi = (item) => {
  emit('change', item.bssid)
}



</script>

<style lang="scss" scoped>
.wifiList {
  padding: 10px 10px;

  header {
    width: 100%;
    text-align: center;
    margin-bottom: 24px;

    h4 {
      font-size: 15px;
      margin-bottom: 5px;
    }

    p {
      color: #666;
      font-size: 12px;
    }
  }

  .list {
    width: 100%;
    height: 500px;
    overflow: hidden;
    overflow-y: auto;

    .item {
      display: flex;
      justify-content: space-between;
      height: 40px;
      margin: 10px 0;
      align-items: center;
      padding: 0 30px;
      border-radius: 10px;

      &:hover {
        background-color: #bebebe67;
      }

      .wifiIcon {
        width: 22px;
        height: 22px;
        background-color: var(--el-color-primary);
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;

        .icon {
          display: flex;
          width: 14px;
          height: 14px;
          background: url('@/icons//wifi-write.svg') no-repeat center;

        }

        margin-right: 10px;
      }

      .title {
        margin-right: auto;
      }

      .suoIcon {
        width: 16px;
        height: 16px;
        background: url('@/icons//锁.svg') no-repeat center;

      }
    }
  }
}
</style>
